/***** BEGIN LICENSE BLOCK *****
 * Version: CPL 1.0/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Common Public
 * License Version 1.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.eclipse.org/legal/cpl-v10.html
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * Copyright (C) 2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
 * 
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the CPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the CPL, the GPL or the LGPL.
 ***** END LICENSE BLOCK *****/
package asruby.lang {

import asruby.Ruby;
import asruby.runtime.IRubyObject;
import asruby.runtime.ThreadContext;

/** 
 *
 */
public class RubyWarnings {
	public static const 	
    	AMBIGUOUS_ARGUMENT:int=1,//AMBIGUOUS_ARGUMENT"),
        ACCESSOR_NOT_INITIALIZED:int=2,//ACCESSOR_NOT_INITIALIZED"),
        ARGUMENT_AS_PREFIX:int=3,//ARGUMENT_AS_PREFIX"),
        ARGUMENT_EXTRA_SPACE:int=4,//ARGUMENT_EXTRA_SPACE"),
        ASSIGNMENT_IN_CONDITIONAL:int=5,//ASSIGNMENT_IN_CONDITIONAL"),
        BIGNUM_FROM_FLOAT_RANGE:int=6,//BIGNUM_FROM_FLOAT_RANGE"),
        BLOCK_BEATS_DEFAULT_VALUE:int=7,//BLOCK_BEATS_DEFAULT_VALUE"),
        BLOCK_NOT_ACCEPTED:int=8,//BLOCK_NOT_ACCEPTED"),
        BLOCK_UNUSED:int=9,//BLOCK_UNUSED"),
        CONSTANT_ALREADY_INITIALIZED:int=10,//CONSTANT_ALREADY_INITIALIZED"),
        CONSTANT_BAD_REFERENCE:int=11,//CONSTANT_BAD_REFERENCE"),
        CVAR_FROM_TOPLEVEL_SINGLETON_METHOD:int=12,//CVAR_FROM_TOPLEVEL_SINGLETON_METHOD"),
        DECLARING_SCLASS_VARIABLE:int=13,//DECLARING_SCLASS_VARIABLE"),
        DEPRECATED_METHOD:int=14,//DEPRECATED_METHOD"),
        DUMMY_VALUE_USED:int=15,//DUMMY_VALUE_USED"),
        END_IN_METHOD:int=16,//END_IN_METHOD"),
        ELSE_WITHOUT_RESCUE:int=17,//ELSE_WITHOUT_RESCUE"),
        EMPTY_IMPLEMENTATION:int=18,//EMPTY_IMPLEMENTATION"),
        ENV_VARS_FROM_CLI_METHOD:int=19,//ENV_VARS_FROM_CLI_METHOD"),
        FIXNUMS_NOT_SYMBOLS:int=20,//FIXNUMS_NOT_SYMBOLS"),
        FLOAT_OUT_OF_RANGE:int=21,//FLOAT_OUT_OF_RANGE"),
        GLOBAL_NOT_INITIALIZED:int=22,//GLOBAL_NOT_INITIALIZED"),
        GROUPED_EXPRESSION:int=23,//GROUPED_EXPRESSION"),
        INEFFECTIVE_GLOBAL:int=24,//INNEFFECTIVE_GLOBAL"),
        INVALID_CHAR_SEQUENCE:int=25,//INVALID_CHAR_SEQUENCE"),
        IVAR_NOT_INITIALIZED:int=26,//IVAR_NOT_INITIALIZED"),
        MAY_BE_TOO_BIG:int=27,//MAY_BE_TOO_BIG"),
        MISCELLANEOUS:int=28,//MISCELLANEOUS"),
        MULTIPLE_VALUES_FOR_BLOCK:int=29,//MULTIPLE_VALUES_FOR_BLOCK"),
        NEGATIVE_NUMBER_FOR_U:int=30,//NEGATIVE_NUMBER_FOR_U"),
        NO_SUPER_CLASS:int=31,//NO_SUPER_CLASS"),
        PARENTHISE_ARGUMENTS:int=32,//PARENTHISE_ARGUMENTS"),
        PROXY_EXTENDED_LATE:int=33,//PROXY_EXTENDED_LATE"),
        STATEMENT_NOT_REACHED:int=34,//STATEMENT_NOT_REACHED"), 
        LITERAL_IN_CONDITIONAL_RANGE:int=35,//LITERAL_IN_CONDITIONAL_RANGE"),
        REDEFINING_DANGEROUS:int=36,//REDEFINING_DANGEROUS"),
        REGEXP_IGNORED_FLAGS:int=37,//REGEXP_IGNORED_FLAGS"),
        REGEXP_LITERAL_IN_CONDITION:int=38,//REGEXP_LITERAL_IN_CONDITION"),
        SAFE_NOT_SUPPORTED:int=39,//SAFE_NOT_SUPPORTED"),
        STRUCT_CONSTANT_REDEFINED:int=40,//STRUCT_CONSTANT_REDEFINED"),
        SYMBOL_AS_INTEGER:int=41,//SYMBOL_AS_INTEGER"),
        SYSSEEK_BUFFERED_IO:int=42,//SYSSEEK_BUFFERED_IO"),
        SYSWRITE_BUFFERED_IO:int=43,//SYSWRITE_BUFFERED_IO"),
        SWALLOWED_IO_EXCEPTION:int=44,//SWALLOWED_IO_EXCEPTION"),
        TOO_MANY_ARGUMENTS:int=45,//TOO_MANY_ARGUMENTS"),
        UNDEFINING_BAD:int=46,//UNDEFINING_BAD"),
        USELESS_EXPRESSION:int=47,//USELESS_EXPRESSION"),
        VOID_VALUE_EXPRESSION:int=48;//VOID_VALUE_EXPRESSION");	
    private  var runtime:Ruby;

    public  function RubyWarnings(runtime:Ruby){
        this.runtime = runtime;
    }

    public  function warn1(id:int, position:Object, message:String, data:Object):void{
        warn2(id, position["file"], position["line"], message, data);
    }

    public  function warn2(id:int, fileName:String, lineNumber:int, message:String, data:Object):void{
        if (runtime.getVerbose().isNil()) return;
    	
        var buffer: String =  "";

        buffer.concat(fileName).concat(':').concat(lineNumber + 1).concat(' ');
        buffer.concat("warning: ").concat(message).concat('\n');
        var errorStream: IRubyObject =  runtime.getGlobalVariables()["$stderr"];
        errorStream.callMethod2(runtime.getCurrentContext(), "write", runtime.newString(buffer.toString()));
    }

    public  function isVerbose():Boolean{
        return runtime.getVerbose().isTrue();
    }

    public  function warn(id:int, message:String, data:Object=null):void{
        var context: ThreadContext =  runtime.getCurrentContext();
        
        warn2(id, context.getFile(), context.getLine(), message, data);
    }

    public  function warning(id:int, message:String, data:Object):void{
        var context: ThreadContext =  runtime.getCurrentContext();

        warning2(id, context.getFile(), context.getLine(), message, data);
    }
    
    public  function warning1(id:int, position:int, message:String, data:Object):void{
        warning2(id, position["file"], position["line"], message, data);
    }

    public  function warning2(id:int, fileName:String, lineNumber:int, message:String, data:Object):void{
        if (isVerbose()) warn2(id, fileName, lineNumber, message, data);
    }
}
}